#include "device_retriever_windows.h"

device_retriever_windows::device_retriever_windows()
{
}


device_retriever_windows::~device_retriever_windows()
{
	destroy_vector(m_device_info_list);
}

bool device_retriever_windows::get_device_list(std::vector< device_info * > ** pptr_list)
{
	std::vector< pcap_device_info * > pcap_device_info_list;
	std::vector< windows_adapters_info * > windows_adapter_info_list;

	bool b = m_pcap_device_retriever.get_device_list(pcap_device_info_list);

	if (!b)
		return b;

	b = m_windows_adapters_retriever.get_adapter_list(windows_adapter_info_list);

	if (!b)
		return b;

	std::vector< pcap_device_info * >::iterator pcap_iter = pcap_device_info_list.begin();
	std::vector< pcap_device_info * >::iterator pcap_itere = pcap_device_info_list.end();

	while (pcap_iter != pcap_itere)
	{
		std::vector< windows_adapters_info * >::iterator windows_iter = windows_adapter_info_list.begin();
		std::vector< windows_adapters_info * >::iterator windows_itere = windows_adapter_info_list.end();

		while (windows_iter != windows_itere)
		{
			if (strstr((*pcap_iter)->get_pcap_device_name(), (*windows_iter)->get_adapter_name()))
			{
				device_info * ptr_info = new device_info;

				ptr_info->set_name((*pcap_iter)->get_pcap_device_name());
				ptr_info->set_friendlyname((*windows_iter)->get_adapter_friendlyname());
				ptr_info->set_description((*windows_iter)->get_adapter_description());

				m_device_info_list.push_back(ptr_info);
			}

			windows_iter++;
		}

		pcap_iter++;
	}

	destroy_vector(pcap_device_info_list);
	destroy_vector(windows_adapter_info_list);

	*pptr_list = &m_device_info_list;

	return true;
}
